<?php
	session_start();
	
//	print_r($_POST);
	require_once('../../lib/'.'BaseDir.inc.htm');
	require_once (EIU_LIB.'View.class.htm');
	require_once('../../lib/'.'DBCommon.class.htm');
	
	
	if(isset($_POST['page']) && !empty($_POST['page'])){
		$startLimit = ($_POST['page']-1)*10;
		$endLimit = 10;
	}
	
	if($_POST['type']==''){
		$condition = "`ComName` LIKE '%".$_POST['compname']."%' AND `ComTel` LIKE'%".$_POST['comptel']."%' AND `ContactName` LIKE '%".$_POST['contname']."%' AND `ContactTel` LIKE '%".$_POST['conttel']."%'";
	}else{
		$condition = "`Type`='".$_POST['type']."' AND `ComName` LIKE '%".$_POST['compname']."%' AND `ComTel` LIKE'%".$_POST['comptel']."%' AND `ContactName` LIKE '%".$_POST['contname']."%' AND `ContactTel` LIKE '%".$_POST['conttel']."%'";
	}
	
	
	$arr = "";

	$count = "SELECT COUNT(*) as count FROM `supplier_tbl` WHERE `isDeleted`=0 AND ".$condition;
	$q = "SELECT * FROM supplier_tbl WHERE `isDeleted`=0 AND ".$condition." ORDER BY `SuppID` LIMIT ".$startLimit.",".$endLimit;

	$oDB = new DBCommon();
	$conn =  $oDB->stl_openConn();
	
	$rs = $oDB->stl_db_select($q, $conn);
	$rs_count = $oDB->stl_db_select($count, $conn);
	if(!empty($rs_count[0]->count)){
		$arr["Count"] = $rs_count[0]->count;
	}
	
	$i = 0;
	if(is_array($rs)){
		foreach($rs as $key=>$value){
			$data1['SuppliID'] = $rs[$key]->SuppID;
			$data1['companyName'] = $rs[$key]->ComName;
			$data1['shortname'] = $rs[$key]->ShortName;
			$data1['address'] = $rs[$key]->ComAddress;
			$data1['companyTel'] = $rs[$key]->ComTel;
			$data1['fax'] = $rs[$key]->ComFax;
			$data1['taxCode'] = $rs[$key]->TaxCode;
			$data1['bankname'] = $rs[$key]->BankName;
			$data1['bankcn'] = $rs[$key]->BankCN;
			$data1['bankacc'] = $rs[$key]->BankAcc;
			$data1['contactName'] = $rs[$key]->ContactName;
			$data1['position'] = $rs[$key]->ContactPosition;
			$data1['personTel'] = $rs[$key]->ContactTel;
			$data1['mobile'] = $rs[$key]->ContactMobile;
			
			$arr["Result"][$i] = $data1;
			$i++;
		}
		echo json_encode($arr);
	}else{
		echo 'NG';
	}

	$oDB->stl_closeConn($conn);
?>
